<!DOCTYPE html>
<html lang="en">

<head>

    <meta charset="UTF-8">

    <link rel="apple-touch-icon" type="image/png"
        href="https://cpwebassets.codepen.io/assets/favicon/apple-touch-icon-5ae1a0698dcc2402e9712f7d01ed509a57814f994c660df9f7a952f3060705ee.png" />
    <meta name="apple-mobile-web-app-title" content="CodePen">

    <link rel="shortcut icon" type="image/x-icon"
        href="https://cpwebassets.codepen.io/assets/favicon/favicon-aec34940fbc1a6e787974dcd360f2c6b63348d4b1f4e06c77743096d55480f33.ico" />

    <link rel="mask-icon" type=""
        href="https://cpwebassets.codepen.io/assets/favicon/logo-pin-8f3771b1072e3c38bd662872f6b673a722f4b3ca2421637d5596661b4e2132cc.svg"
        color="#111" />


    <title>CodePen - 圆形进度条</title>

    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">



    <style>
        #canvas {
            display: block;
            margin: 0 auto;
        }
    </style>

    <script>
        window.console = window.console || function (t) { };
    </script>



    <script>
        if (document.location.search.match(/type=embed/gi)) {
            window.parent.postMessage("resize", "*");
        }
    </script>


</head>

<body translate="no">
    <canvas id="canvas" width="300" height="300">
        <p>抱歉，您的浏览器不支持canvas</p>
    </canvas>
    <script
        src="https://cpwebassets.codepen.io/assets/common/stopExecutionOnTimeout-157cd5b220a5c80d4ff8e0e70ac069bffd87a61252088146915e8726e5d9f147.js"></script>


    <script id="rendered-js">
        /* by www.geekwen.com */
        var canvas = document.getElementById("canvas"),
            ctx = canvas.getContext("2d"),
            percent = 75.0, // 最终百分比
            circleX = canvas.width / 2, // 中心x坐标
            circleY = canvas.height / 2, // 中心y坐标
            radius = 100, // 圆环半径
            lineWidth = 20, // 圆形线条的宽度
            fontSize = 50; // 字体大小

        // 画圆
        function circle(cx, cy, r) {
            ctx.beginPath();
            ctx.moveTo(cx + r, cy);
            ctx.lineWidth = lineWidth;
            ctx.strokeStyle = '#eee';
            ctx.arc(cx, cy, r, 0, Math.PI * 2);
            ctx.closePath();
            ctx.stroke();
        }

        // 画弧线
        function sector(cx, cy, r, startAngle, endAngle, anti) {
            ctx.beginPath();
            ctx.moveTo(cx, cy + r); // 从圆形底部开始画
            ctx.lineWidth = lineWidth;

            // 渐变色 - 可自定义
            var linGrad = ctx.createLinearGradient(
                circleX, circleY - radius - lineWidth, circleX, circleY + radius + lineWidth);

            linGrad.addColorStop(0.0, '#ec847a');
            linGrad.addColorStop(0.5, '#9bc4eb');
            linGrad.addColorStop(1.0, '#eccd23');
            ctx.strokeStyle = linGrad;

            // 圆弧两端的样式
            ctx.lineCap = 'round';

            // 圆弧
            ctx.arc(
                cx, cy, r,
                startAngle * (Math.PI / 180.0) + Math.PI / 2,
                endAngle * (Math.PI / 180.0) + Math.PI / 2,
                anti);

            ctx.stroke();
        }

        // 刷新
        function loading() {
            if (process >= percent) {
                clearInterval(circleLoading);
            }

            // 清除canvas内容
            ctx.clearRect(0, 0, circleX * 2, circleY * 2);

            // 中间的字
            ctx.font = fontSize + 'px April';
            ctx.textAlign = 'center';
            ctx.textBaseline = 'middle';
            ctx.fillStyle = '#999';
            ctx.fillText(parseFloat(process).toFixed(0) + '%', circleX, circleY);

            // 圆形
            circle(circleX, circleY, radius);

            // 圆弧
            sector(circleX, circleY, radius, 0, process / 100 * 360);

            // 控制结束时动画的速度
            if (process / percent > 0.90) {
                process += 0.30;
            } else if (process / percent > 0.80) {
                process += 0.55;
            } else if (process / percent > 0.70) {
                process += 0.75;
            } else {
                process += 1.0;
            }
        }

        var process = 0.0; // 进度
        var circleLoading = window.setInterval(function () {
            loading();
        }, 20);
//# sourceURL=pen.js
    </script>



</body>

</html>